﻿/// <reference path="jquery-1.3.1.js" />
function ClientProxyDTO(methodName,serviceName, dto, successFunction, errorFunction) {
    $.ajax({
        type: "POST",
        url: serviceName + "/" + methodName,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(dto),
        dataType: "json",
        processData: false,
        success: function(msgg) {
            if (msgg == null) {
                alert("msgg is null");
            }
            /*var msg = JSON.parse(msgg, function(key, value) {
                var a;
                if (value != null) {
                    if (value.toString().indexOf('Date') >= 0) {
                        a = /^\/Date\((-?[0-9]+)\)\/$/.exec(value);
                        if (a) {
                            var dt = new Date(parseInt(a[1], 10));
                            return (dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear();
                        }
                    }
                    return value;
                }
            });*/
            //successFunction(msg);
            successFunction(msgg);
        },
        error: function(xhr, status, error) {
            errorFunction(xhr, status, error);
        }
    });
    return false;
}

//Simple function without DTO
function ClientProxySimple(methodName, serviceName, paramArray, successFunction, errorFunction) {
    var paramList = '';

    if (paramArray.length > 0) {
        for (var i = 0; i < paramArray.length; i += 2) {
            if (paramList.length > 0) paramList += ',';
            paramList += '"' + paramArray[i] + '"' + ':' + '"' + paramArray[i + 1] + '"';
        }
    }
    paramList = '{' + paramList + '}'; $.ajax({
        type: "POST",
        url: serviceName + "/" + methodName,
        contentType: "application/json; charset=utf-8",
        data: paramList,
        dataType: "json",
        processData: false,
        success: function(msgg) {
            if (msgg == null) {
                alert("msgg is null");
            }
            var msg = JSON.parse(msgg, function(key, value) {
            var a;
            if (value != null) {
            if (value.toString().indexOf('Date') >= 0) {
            a = /^\/Date\((-?[0-9]+)\)\/$/.exec(value);
            if (a) {
            var dt = new Date(parseInt(a[1], 10));
            return (dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear();
            }
            }
            return value;
            }
            });
            successFunction(msg);
            //successFunction(msgg);
        },
        error: function(xhr, status, error) {
            errorFunction(xhr, status, error);
        }
    });
    return false;
}